/*
 * @Description:
 * @Author: qingyang
 * @Date: 2021-06-01 13:13:26
 * @LastEditors: chenju
 * @LastEditTime: 2022-12-12 11:07:10
 */
import type { MenuList } from '@/utils/user.utils'
import type { RouteRecordRaw } from 'vue-router'
export interface ITree {
  id: any
  name: string
  path?: string
  icon?: string
  children?: null | ITree[]
}

export interface SideMenuItem extends ITree {
  topMenu: string
}

export type IUserType =
  | 'JWT'
  | 'CARBON'
  | 'GEELY'
  | 'FEISHU'
  | 'DINGTALK'
  | 'SUPPLIER'
  | 'OA'
  | 'SSO'

export interface UserState {
  userInfo: any
  // 用户所属组织
  userOrganizations: string[]
  roles: string[]
  /**
   * 菜单树，全部
   */
  menuTree: ITree[]
  /**
   * 顶部菜单 树
   */
  topMenus: ITree[]
  /**
   * 侧边菜单 树
   */
  sideMenus: ITree[] | null
  /**
   * 侧边菜单 列表
   */
  sideMenuList: SideMenuItem[]
  /**
   * 菜单列表
   */
  menuList: MenuList
  routes: RouteRecordRaw[]
  loginVisible: boolean
  isLogin: boolean
  // 按钮权限列表
  permissions: string[]
  // 用户类型
  userType: IUserType
  // 是否是从eps系统通过url token登录的
  isJwtTokenLoginFlag: boolean
  // 订阅版本
  subProductVersion: StringObject
}

export const state: UserState = {
  userInfo: {},
  userOrganizations: [],
  roles: [],
  menuTree: [],
  topMenus: [],
  sideMenus: [],
  sideMenuList: [],
  loginVisible: false,
  isLogin: false,
  routes: [],
  permissions: [],
  menuList: [],
  userType: window.localStorage.getItem('user-type')
    ? (window.localStorage.getItem('user-type') as IUserType)
    : 'CARBON',
  isJwtTokenLoginFlag: window.localStorage.getItem('isJwtTokenLoginFlag') ? true : false,
  // 订阅版本
  subProductVersion: {}
}
